home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-08 | 32.9 KB | 1,113 lines |
- //========================================================================================
- //
- // File: ContainerSel.cpp
- // Release Version: $ 1.0d11 $
- //
- // Author: Henri Lamiraux
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Container.hpp"
-
- #ifndef CONTAINERSEL_H
- #include "ContainerSel.h"
- #endif
-
- #ifndef CONTAINERFRM_H
- #include "ContainerFrm.h"
- #endif
-
- #ifndef CONTAINERPART_H
- #include "ContainerPart.h"
- #endif
-
- #ifndef BASESHP_H
- #include "BaseShp.h"
- #endif
-
- #ifndef BOUNDSHP_H
- #include "BoundShp.h"
- #endif
-
- #ifndef LINESHP_H
- #include "LineShp.h"
- #endif
-
- #ifndef OVALSHP_H
- #include "OvalShp.h"
- #endif
-
- #ifndef RECTSHP_H
- #include "RectShp.h"
- #endif
-
- #ifndef RRECTSHP_H
- #include "RRectShp.h"
- #endif
-
- #ifndef TEXTSHP_H
- #include "TextShp.h"
- #endif
-
- #ifndef CONTAINERCLIP_H
- #include "ContainerClip.h"
- #endif
-
- #ifndef CONTAINERPRXY_H
- #include "ContainerPrxy.h"
- #endif
-
- #ifndef UTILS_H
- #include "Utils.h"
- #endif
-
- #ifndef SHPTRAKR_H
- #include "ShpTrakr.h"
- #endif
-
- #ifndef CONTAINERCMDS_H
- #include "ContainerCmds.h"
- #endif
-
- #ifndef CONTAINERLINK_H
- #include "ContainerLink.h"
- #endif
-
- #ifndef CONTAINERPROMISE_H
- #include "ContainerPromise.h"
- #endif
-
- // ----- Part Layer -----
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWORDCOL_H
- #include "FWOrdCol.h"
- #endif
-
- #ifndef FWSUSINK_H
- #include "FWSUSink.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment container2
- #endif
-
- //========================================================================================
- // class CContainerSelection
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::CContainerSelection
- //----------------------------------------------------------------------------------------
-
- CContainerSelection::CContainerSelection(Environment* ev, CContainerPart* containerPart):
- FW_CEmbeddingSelection(ev, TRUE, TRUE),
- fContainerPart(containerPart),
- fUpdateShape(NULL),
- fProxyShapeCount(0),
- fFrozenCount(0),
- fCount(0),
- fCollection(NULL),
- fWorkingHandle(FW_kZeroRect, FW_kFill)
- {
- fCollection = new FW_CPrivOrderedCollection;
- fWorkingHandle.SetInk(FW_kInvertInk);
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::~CContainerSelection
- //----------------------------------------------------------------------------------------
-
- CContainerSelection::~CContainerSelection()
- {
- if (fUpdateShape)
- fUpdateShape->Release(somGetGlobalEnvironment());
-
- delete fCollection;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::WhichHandle
- //----------------------------------------------------------------------------------------
-
- CBaseShape* CContainerSelection::WhichHandle(Environment* ev, FW_CGraphicContext& gc, const FW_CPoint& mouse, short& whichHandle) const
- {
- whichHandle = 0;
-
- if (fCount != 0)
- {
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- whichHandle = shape->WhichHandle(gc, mouse);
- if (whichHandle != 0)
- return shape;
- }
- }
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::RenderSelectionHandles
- //----------------------------------------------------------------------------------------
-
- void CContainerSelection::RenderSelectionHandles(Environment* ev, FW_CGraphicContext& gc)
- {
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- shape->RenderHandles(gc);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::RenderAllHandles
- //----------------------------------------------------------------------------------------
-
- void CContainerSelection::RenderAllHandles(Environment* ev, FW_CFrame* frame)
- {
- if (fCount != 0)
- {
- FW_CFrameFacetIterator ite(ev, frame);
- for (ODFacet* facet = (ODFacet*)ite.First(ev); ite.IsNotComplete(ev); facet = (ODFacet*)ite.Next(ev))
- {
- FW_CViewContext vc(ev, frame->GetContentView(ev), facet);
- RenderSelectionHandles(ev, vc);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::RenderHandles
- //----------------------------------------------------------------------------------------
-
- void CContainerSelection::RenderHandles(Environment* ev, CBaseShape* shape)
- {
- FW_CPresentationFrameIterator ite(GetPresentation(ev));
- for (FW_CFrame* frame = ite.First(); ite.IsNotComplete(); frame = ite.Next())
- {
- if (frame->IsActive(ev))
- {
- FW_CFrameFacetIterator i(ev, frame);
- for (ODFacet* facet = i.First(ev); i.IsNotComplete(ev); facet = i.Next(ev))
- {
- FW_CViewContext vc(ev, frame->GetContentView(ev), facet);
- shape->RenderHandles(vc);
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::CloseSelection
- //----------------------------------------------------------------------------------------
-
- void CContainerSelection::CloseSelection(Environment* ev)
- {
- while (fCollection->Count() != 0)
- {
- CBaseShape *shape = (CBaseShape*)fCollection->First();
- DoRemove(ev, shape);
- RenderHandles(ev, shape); // turn off
- }
-
- CalcCache(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::AddToSelection
- //----------------------------------------------------------------------------------------
-
- void CContainerSelection::AddToSelection(Environment* ev, CBaseShape* theShape, FW_Boolean renderHandles)
- {
- if (theShape != NULL)
- {
- DoAdd(ev, theShape);
- if (renderHandles)
- RenderHandles(ev, theShape); // Turn on
- }
-
- CalcCache(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::RemoveFromSelection
- //----------------------------------------------------------------------------------------
-
- void CContainerSelection::RemoveFromSelection(Environment* ev, CBaseShape* shape, FW_Boolean renderHandles)
- {
- if (shape != NULL)
- {
- DoRemove(ev, shape);
- if (renderHandles)
- RenderHandles(ev, shape); // Turn Off
- }
-
- CalcCache(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::DoAdd
- //----------------------------------------------------------------------------------------
-
- void CContainerSelection::DoAdd(Environment* ev, CBaseShape *shape)
- {
- shape->SelectShape(ev, TRUE);
- fCollection->AddLast(shape);
- fCount++;
- if (shape->GetShapeType() == kProxyShape)
- fProxyShapeCount++;
- if (shape->IsFrozen())
- fFrozenCount++;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::DoRemove
- //----------------------------------------------------------------------------------------
-
- void CContainerSelection::DoRemove(Environment* ev, CBaseShape *shape)
- {
- shape->SelectShape(ev, FALSE);
- fCollection->Remove(shape);
- fCount--;
- if (shape->GetShapeType() == kProxyShape)
- fProxyShapeCount--;
- if (shape->IsFrozen())
- fFrozenCount--;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::ClearSelection
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CContainerSelection::ClearSelection(Environment* ev)
- {
- CBaseShape *shape;
- while (fCollection->Count() != 0)
- {
- shape = (CBaseShape*)fCollection->First();
- shape->CheckPromise(ev, fContainerPart);
-
- DoRemove(ev, shape); // Remove from Selection list
- fContainerPart->RemoveShape(ev, shape); // Remove from shape list
- }
-
- CContainerFacetClipper facetClipper(ev, fContainerPart);
- facetClipper.Clip(ev, GetPresentation(ev), fUpdateShape);
- GetPresentation(ev)->Invalidate(ev, fUpdateShape);
-
- CalcCache(ev);
-
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::SelectAll
- //----------------------------------------------------------------------------------------
-
- void CContainerSelection::SelectAll(Environment* ev)
- {
- FW_CFrame* activeFrame = fContainerPart->GetActiveFrame(ev);
-
- RenderAllHandles(ev, activeFrame);
-
- FW_COrderedCollectionIterator ite(fContainerPart->GetShapeList());
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- if (!shape->IsSelectedShape())
- DoAdd(ev, shape);
- }
-
- RenderAllHandles(ev, activeFrame);
-
- CalcCache(ev);
-
- fContainerPart->SetTool(ev, kSelectTool);
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::IsEmpty
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CContainerSelection::IsEmpty(Environment* ev) const
- {
- return fCount == 0;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::IsSelectionOnlyOneProxy
- //----------------------------------------------------------------------------------------
-
- FW_MProxy* CContainerSelection::IsSelectionOnlyOneProxy(Environment* ev) const
- {
- if (fCount == 1 && fProxyShapeCount == 1)
- {
- return (CProxyShape*)fCollection->First();
- }
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::DoExternalizeSelection
- //----------------------------------------------------------------------------------------
- void CContainerSelection::DoExternalizeSelection(Environment* ev,
- ODStorageUnit* destinationSU,
- FW_CCloneInfo* cloneInfo)
- {
- // ----- Create an archive for our shapes -----
- FW_CStorageUnitSink sink(destinationSU, kODPropContents, fContainerPart->GetPartKind(ev));
- CContainerWritableStream archive(ev, &sink, cloneInfo);
-
- // ----- Write number of shapes -----
- unsigned long count = fCollection->Count();
- archive << count;
-
- // ----- Write top left offset -----
- FW_CFixed offset = FW_IntToFixed(0);
- archive << offset;
- archive << offset;
-
- // ----- Write shapes -----
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape* theShape = (CBaseShape*)ite.First(); ite.IsNotComplete(); theShape = (CBaseShape*)ite.Next())
- {
- FW_WRITE_DYNAMIC_OBJECT(archive, theShape, CBaseShape);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::DoInternalizeSelection
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CContainerSelection::DoInternalizeSelection(Environment* ev,
- ODStorageUnit* sourceSU,
- FW_CCloneInfo* cloneInfo)
- {
- if (sourceSU->Exists(ev, kODPropContents, fContainerPart->GetPartKind(ev), 0))
- {
- // ----- Close First the current selection -----
- CloseSelection(ev);
-
- // ----- [HLX] force fulfill promises Otherwise bug in locks
- sourceSU->Focus(ev, kODPropContents, kODPosUndefined, fContainerPart->GetPartKind(ev), 0, kODPosUndefined);
- sourceSU->GetSize(ev);
-
- // ----- Create an archive object for the content property -----
- FW_CStorageUnitSink sink(sourceSU, kODPropContents, fContainerPart->GetPartKind(ev));
- CContainerReadableStream archive(ev, fContainerPart, &sink, cloneInfo);
-
- // ----- Read number of shapes -----
- unsigned long count;
- archive >> count;
-
- // ----- Read top left offset -----
- FW_CFixed xTopLeft, yTopLeft;
- archive >> xTopLeft;
- archive >> yTopLeft;
-
- // ----- Then read in the new selection -----
- for (unsigned short i = 0; i<count; i++)
- {
- CBaseShape* theShape = NULL;
- FW_READ_DYNAMIC_OBJECT(archive, &theShape, CBaseShape);
- FW_ASSERT(theShape);
-
- // ----- Add it at the right place -----
- fContainerPart->AddShape(ev, theShape);
-
- this->DoAdd(ev, theShape); // Add to the selection list
- }
-
- CalcCache(ev);
-
- return TRUE;
- }
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::InsertNewPart
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CContainerSelection::InsertNewPart(Environment* ev, FW_CFrame* scopeFrame)
- {
- FW_Boolean result = FW_CEmbeddingSelection::InsertNewPart(ev, scopeFrame);
-
- if (result)
- AdjustSelectionAfterPaste(ev, scopeFrame);
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::AdjustSelectionAfterPaste
- //----------------------------------------------------------------------------------------
-
- FW_CPoint CContainerSelection::AdjustSelectionAfterPaste(Environment* ev, FW_CFrame* scopeFrame)
- {
- FW_ASSERT(scopeFrame);
-
- fContainerPart->SetTool(ev, kSelectTool);
-
- FW_CRect frameBounds = scopeFrame->GetContentView(ev)->GetBounds(ev);
- frameBounds.Place(FW_kFixed0, FW_kFixed0);
- scopeFrame->GetContentView(ev)->ViewToViewContent(ev, frameBounds);
-
- FW_CRect box(fDragRect);
- box.PlaceInCenter(frameBounds);
-
- FW_CPoint result(box.left - fDragRect.left, box.top - fDragRect.top);
- OffsetSelection(ev, result.x, result.y);
-
- CContainerFacetClipper facetClipper(ev, fContainerPart);
- facetClipper.Clip(ev, GetPresentation(ev), fUpdateShape);
- GetPresentation(ev)->Invalidate(ev, fUpdateShape);
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::Resize
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CContainerSelection::Resize(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- if (fClickedHandle == 0)
- return FALSE;
-
- if (!this->IsOKtoEdit(ev)) // can't resize read only part
- {
- FW_Beep();
- return TRUE;
- }
-
- if (!theMouseEvent.WaitUntilMouseMoved(ev))
- return TRUE;
-
- ODFacet* facet = theMouseEvent.GetFacet(ev);
- FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
-
- CBaseShape* anchorShape = GetAnchorShape();
-
- FW_PInk resizeInk(FW_kRGBBlack, FW_kRGBWhite, FW_kXOr);
- FW_PStyle resizeStyle(anchorShape->GetResizeStyle());
-
- CResizeTracker resizeTracker(ev, frame->GetContentView(ev), facet, anchorShape, fClickedHandle, resizeInk, resizeStyle, TRUE);
- if (resizeTracker.Track(ev, theMouseEvent))
- {
- GetPresentation(ev)->Invalidate(ev, fUpdateShape);
-
- FW_CPoint lastLocation;
- resizeTracker.GetLastLocation(lastLocation);
- FW_CRect srcRect, dstRect;
- anchorShape->GetMapRects(fClickedHandle, lastLocation, srcRect, dstRect);
-
- CResizeShapeCommand* cmd = FW_NEW(CResizeShapeCommand,
- (ev, fContainerPart, frame, this,
- srcRect, dstRect));
- fContainerPart->ExecuteCommand(ev, cmd);
- }
- else
- {
- FW_CViewContext vc(ev, frame->GetContentView(ev), facet);
-
- anchorShape->CalcHandle(fClickedHandle, &fWorkingHandle);
- fWorkingHandle.Render(vc); // recontainer the handle
- }
-
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::CalcCache
- //----------------------------------------------------------------------------------------
-
- void CContainerSelection::CalcCache(Environment* ev)
- {
- fDragRect.Clear();
-
- if (fUpdateShape == NULL)
- fUpdateShape = ::FW_NewODShape(ev);
-
- if (fCount == 0)
- return;
-
- FW_CAcquiredODShape aqTempShape = ::FW_NewODShape(ev);
- FW_CRect tempRect;
-
- FW_Boolean first = TRUE;
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- shape->GetDragRect(tempRect);
- shape->GetUpdateBox(ev, aqTempShape);
- if (first)
- {
- fDragRect = tempRect;
- fUpdateShape->CopyFrom(ev, aqTempShape);
- }
- else
- {
- fDragRect |= tempRect;
- fUpdateShape->Union(ev, aqTempShape);
- }
-
- first = FALSE;
- }
-
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::CreateSelectionShape
- //----------------------------------------------------------------------------------------
-
- ODShape* CContainerSelection::CreateSelectionShape(Environment* ev, ODFacet* facet, FW_CFrame* frame) const
- {
- FW_UNUSED(frame);
- FW_UNUSED(facet);
-
- ODShape* shape = ::FW_NewODShape(ev, fDragRect);
- return shape;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::CreateSelectionShape
- //----------------------------------------------------------------------------------------
-
- ODShape* CContainerSelection::CreateSelectionOutline(Environment* ev, ODFacet* facet, FW_CFrame* frame) const
- {
- ODShape* outline = GetAnchorShape()->CreateShapeOutline(ev);
-
- if (fCount > 1)
- {
- FW_CAcquiredODShape shapeOutline = FW_CEmbeddingSelection::CreateSelectionOutline(ev, facet, frame);
- outline->Union(ev, shapeOutline);
- }
-
- return outline;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::MapSelection
- //----------------------------------------------------------------------------------------
-
- void CContainerSelection::MapSelection(Environment* ev, const FW_CRect& srcRect, const FW_CRect& dstRect)
- {
- FW_CAcquiredODShape aqUnionShape(fUpdateShape->Copy(ev));
-
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- shape->MapShape(ev, fContainerPart, srcRect, dstRect);
- }
-
- CalcCache(ev);
-
- aqUnionShape->Union(ev, fUpdateShape);
-
- CContainerFacetClipper facetClipper(ev, fContainerPart);
- facetClipper.Clip(ev, GetPresentation(ev), aqUnionShape);
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::CreateSelectionFrameShape
- //----------------------------------------------------------------------------------------
-
- ODShape* CContainerSelection::CreateSelectionFrameShape(Environment* ev) const
- {
-
- FW_CRect selectionRect(fDragRect);
- selectionRect.Place(FW_kZeroPoint);
-
- ODShape* selectionShape = ::FW_NewODShape(ev, selectionRect);
- return selectionShape;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::OffsetSelection
- //----------------------------------------------------------------------------------------
-
- void CContainerSelection::OffsetSelection(Environment* ev, FW_CFixed xDelta, FW_CFixed yDelta)
- {
- FW_CAcquiredODShape aqUnionShape(fUpdateShape->Copy(ev));
-
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- shape->OffsetShape(ev, xDelta, yDelta);
- }
-
- CalcCache(ev);
-
- aqUnionShape->Union(ev, fUpdateShape);
-
- CContainerFacetClipper facetClipper(ev, fContainerPart);
- facetClipper.Clip(ev, GetPresentation(ev), aqUnionShape);
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::SelectWithRectangle
- //----------------------------------------------------------------------------------------
-
- void CContainerSelection::SelectWithRectangle(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- CRectShape rectShape; // Create a rect shape on the stack
- FW_PStyle trackStyle(FW_IntToFixed(1), FW_kAntPat);
- FW_PInk trackInk(FW_kRGBBlack, FW_kRGBWhite, FW_kXOr);
- rectShape.ChangeRenderVerb(ev, fContainerPart, kFrameOnly);
- rectShape.SetFrameInk(trackInk);
- rectShape.SetFrameStyle(trackStyle);
-
- ODFacet* facet = theMouseEvent.GetFacet(ev);
- FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
-
- CShapeTracker tracker(ev, frame->GetContentView(ev), facet, &rectShape, FALSE);
- if (tracker.Track(ev, theMouseEvent))
- {
- FW_Boolean isShift = theMouseEvent.IsExtendModifier(ev);
- FW_CRect selectRect;
- rectShape.GetRectGeometry(selectRect);
-
- FW_COrderedCollectionIterator ite(fContainerPart->GetShapeList());
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- if (shape->InSelectionRect(selectRect))
- {
- if (shape->IsSelectedShape())
- {
- if (isShift)
- {
- DoRemove(ev, shape);
- RenderHandles(ev, shape); // Turn Off
- }
- }
- else
- {
- DoAdd(ev, shape);
- RenderHandles(ev, shape); // Turn on
- }
- }
- else if (shape->IsSelectedShape() && !isShift)
- {
- DoRemove(ev, shape);
- RenderHandles(ev, shape); // Turn Off
- }
- }
- CalcCache(ev);
- }
- else
- {
- if (!theMouseEvent.IsExtendModifier(ev))
- CloseSelection(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::ChangeSelectionPenSize
- //----------------------------------------------------------------------------------------
-
- void CContainerSelection::ChangeSelectionPenSize(Environment* ev, FW_CFixed newPenSize)
- {
- FW_CAcquiredODShape aqUnionShape(fUpdateShape->Copy(ev));
-
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- shape->ChangePenSize(ev, fContainerPart, newPenSize);
- this->RecontainerShape(ev, shape);
- }
-
- SelectionChanged(ev);
- CalcCache(ev);
-
- aqUnionShape->Union(ev, fUpdateShape);
-
- CContainerFacetClipper facetClipper(ev, fContainerPart);
- facetClipper.Clip(ev, GetPresentation(ev), aqUnionShape);
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::ChangeSelectionColor
- //----------------------------------------------------------------------------------------
-
- void CContainerSelection::ChangeSelectionColor(Environment* ev, const FW_CColor& color, FW_Boolean changeFill)
- {
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- if (changeFill)
- shape->ChangeFillColor(ev, fContainerPart, color);
- else
- shape->ChangeFrameColor(ev, fContainerPart, color);
-
- this->RecontainerShape(ev, shape);
- }
-
- SelectionChanged(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::ChangeSelectionPattern
- //----------------------------------------------------------------------------------------
-
- void CContainerSelection::ChangeSelectionPattern(Environment* ev, const FW_PPattern& pattern, FW_Boolean changeFill)
- {
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- if (changeFill)
- shape->ChangeFillPattern(ev, fContainerPart, pattern);
- else
- shape->ChangeFramePattern(ev, fContainerPart, pattern);
-
- this->RecontainerShape(ev, shape);
- }
-
- SelectionChanged(ev);
- }
-
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::ChangeSelectionRenderVerb
- //----------------------------------------------------------------------------------------
-
- void CContainerSelection::ChangeSelectionRenderVerb(Environment* ev, unsigned short newRenderVerb)
- {
- FW_CAcquiredODShape aqUnionShape(fUpdateShape->Copy(ev));
-
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- shape->ChangeRenderVerb(ev, fContainerPart, newRenderVerb);
- this->RecontainerShape(ev, shape);
- }
-
- SelectionChanged(ev);
- CalcCache(ev);
-
- aqUnionShape->Union(ev, fUpdateShape);
-
- CContainerFacetClipper facetClipper(ev, fContainerPart);
- facetClipper.Clip(ev, GetPresentation(ev), aqUnionShape);
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::RecontainerShape
- //----------------------------------------------------------------------------------------
-
- void CContainerSelection::RecontainerShape(Environment* ev, CBaseShape *shape)
- {
- FW_CAcquiredODShape aqInvalidShape = ::FW_NewODShape(ev);
- shape->GetUpdateBox(ev, aqInvalidShape);
- GetPresentation(ev)->Invalidate(ev, aqInvalidShape);
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::SetFrozen
- //----------------------------------------------------------------------------------------
-
- void CContainerSelection::SetFrozen(Environment* ev, FW_Boolean state)
- {
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- if (shape->SetFrozen(state))
- {
- state ? fFrozenCount++ : fFrozenCount--;
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::NewPromise
- //----------------------------------------------------------------------------------------
-
- FW_CPromise* CContainerSelection::NewPromise(Environment* ev, ODUpdateID updateID, FW_EStorageKinds storageKind, FW_CFrame* scopeFrame, ODCloneKind cloneKind)
- {
- FW_UNUSED(cloneKind);
-
- if (storageKind == FW_kLinkStorage)
- return NULL;
-
- return new CContainerPromise(ev, updateID, storageKind, fContainerPart, scopeFrame, this);
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::SelectionChanged
- //----------------------------------------------------------------------------------------
-
- void CContainerSelection::SelectionChanged(Environment* ev)
- {
- FW_CPrivOrderedCollection temp;
-
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- if (shape->IsPublished())
- {
- FW_Boolean add = TRUE;
- FW_COrderedCollectionIterator tempIte(&temp);
- for (CContainerPublishLink* link = (CContainerPublishLink*)tempIte.First(); tempIte.IsNotComplete(); link = (CContainerPublishLink*)tempIte.Next())
- {
- if (shape->GetPublishLink() == link)
- {
- add = FALSE;
- break;
- }
- }
-
- if (add)
- temp.AddLast(shape->GetPublishLink());
- }
- }
-
- FW_COrderedCollectionIterator tempIte(&temp);
- for (CContainerPublishLink* link = (CContainerPublishLink*)tempIte.First(); tempIte.IsNotComplete(); link = (CContainerPublishLink*)tempIte.Next())
- {
- link->ContentUpdated(ev, fContainerPart->GetSession(ev)->UniqueUpdateID(ev));
- }
-
- temp.RemoveAll();
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::IsSelectionPublishable
- //----------------------------------------------------------------------------------------
- // We don't allow linking if one of the shape is already published
-
- FW_Boolean CContainerSelection::IsSelectionPublishable(Environment* ev)
- {
- FW_Boolean result = TRUE;
-
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- if (shape->IsPublished())
- {
- result = FALSE;
- break;
- }
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::CanSubscribe
- //----------------------------------------------------------------------------------------
- FW_Boolean CContainerSelection::CanSubscribe(Environment* ev, ODPasteAsMergeSetting& setting)
- {
- FW_Boolean result = TRUE;
-
- if (fAllowSubscribe)
- {
- setting = kODPasteAsMerge; // default is no embedding
-
- FW_COrderedCollectionIterator ite(fCollection);
- for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- if (shape->IsSubscribed())
- {
- result = FALSE;
- break;
- }
- }
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::IsMouseInDraggableItem
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CContainerSelection::IsMouseInDraggableItem(Environment* ev, FW_CFrame* frame,
- const FW_CMouseEvent& theMouseEvent, FW_Boolean inBackground)
- {
- fClickedHandle = 0;
- fAnchorShape = NULL;
-
- if (fContainerPart->GetTool() != kSelectTool)
- return FALSE;
-
- FW_CViewContext vc(ev, frame->GetContentView(ev), theMouseEvent.GetFacet(ev));
-
- // ----- Look first for a handle -----
- FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
- frame->GetContentView(ev)->FrameToViewContent(ev, where);
-
- CBaseShape* clickedShape = WhichHandle(ev, vc, where, fClickedHandle);
- if (clickedShape != NULL)
- {
- fAnchorShape = clickedShape;
- return FALSE; // if in a handle we won't drag
- }
-
- // ----- then look for a selected shape -----
- fAnchorShape = fContainerPart->WhichShape(ev, vc, theMouseEvent, TRUE);
-
- return fAnchorShape != NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::UpdateSelectionOnMouseDown
- //----------------------------------------------------------------------------------------
-
- void CContainerSelection::UpdateSelectionOnMouseDown(Environment* ev,
- const FW_CMouseEvent& mouseEvent,
- ODFacet* embeddedFacet,
- FW_Boolean inEmbeddedFrameBorder,
- FW_Boolean inBackground)
- {
- if (inEmbeddedFrameBorder)
- {
- fClickedHandle = 0;
- fAnchorShape = NULL;
-
- CProxyShape *theShape = (CProxyShape*)fContainerPart->GetProxy(ev, embeddedFacet->GetFrame(ev));
-
- // [HLX] I have to remove this assert for now. See FW_CFrame::FocusStateChanged
- // FW_ASSERT(!theShape->IsSelectedShape());
- CloseSelection(ev); // Should already be closed
- AddToSelection(ev, theShape, TRUE);
-
- fAnchorShape = theShape;
- }
- else if (fContainerPart->GetTool() == kSelectTool)
- {
- FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, mouseEvent.GetFacet(ev)->GetFrame(ev));
- FW_CViewContext vc(ev, frame->GetContentView(ev), mouseEvent.GetFacet(ev));
-
- CBaseShape* clickedShape = fContainerPart->WhichShape(ev, vc, mouseEvent, FALSE);
- if (clickedShape)
- {
- if (mouseEvent.IsExtendModifier(ev))
- {
- if (clickedShape->IsSelectedShape())
- RemoveFromSelection(ev, clickedShape, TRUE);
- else
- AddToSelection(ev, clickedShape, TRUE);
- }
- else if (!clickedShape->IsSelectedShape())
- {
- CloseSelection(ev);
- AddToSelection(ev, clickedShape, TRUE);
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::DeleteSelection
- //----------------------------------------------------------------------------------------
- void CContainerSelection::DeleteSelection(Environment* ev)
- {
- CBaseShape *shape;
- while (fCollection->Count() != 0)
- {
- shape = (CBaseShape*)fCollection->First();
- DoRemove(ev, shape); // Remove from Selection list
- fContainerPart->DeleteShape(ev, shape); // Remove from shape list
- delete shape;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::IsOKtoEdit
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CContainerSelection::IsOKtoEdit(Environment* ev)
- {
- if (fContainerPart->IsReadOnly(ev)) // can't edit read only part
- return FALSE;
-
- // check whether any of the selected shapes is in a link destination
- FW_COrderedCollectionIterator iter(fCollection);
- for (CBaseShape *shape = (CBaseShape*)iter.First(); iter.IsNotComplete(); shape = (CBaseShape*)iter.Next())
- {
- if (shape->IsSubscribed())
- return FALSE; // can't edit a subscribed shape
- }
-
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerSelection::GetSelectionPenSize
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CContainerSelection::GetSelectionPenSize(Environment* ev, FW_CFixed& penSize)
- {
- FW_COrderedCollectionIterator iter(fCollection);
- FW_Boolean first = TRUE;
- for (CBaseShape *shape = (CBaseShape*)iter.First(); iter.IsNotComplete(); shape = (CBaseShape*)iter.Next())
- {
- if (first)
- {
- penSize = shape->GetPenSize();
- first = FALSE;
- }
- else
- {
- if (shape->GetPenSize() != penSize)
- return FALSE;
- }
- }
-
- return TRUE;
- }
-